﻿function MouseOver(obj) {
    $(obj).prop("class", "icoOver");
    //$("th", $(obj).parent().parent().parent()).prop("class", "tdOver");
}
function MouseOut(obj) {
    $(obj).prop("class", "icoNormal");
    //$("th", $(obj).parent().parent().parent()).prop("class", "tdNormal");
}
function MenuOnMouseOver(obj) {
    obj.className = 'menubar_button';
}

function MenuOnMouseOut(obj) {
    obj.className = 'menubar_button_on';
}
function loadStepView(CurStepIdx) {
    var bar = $("#sideBar");
    if (bar.length > 0) {
        $("a", bar).each(function () { $(this).prop("class", "lnkNor"); })

        $("a", bar).eq(CurStepIdx).prop("class", "lnkCur");
    }
}
/*
说明：工具栏按钮触发的js事件
    
*/
function btnTool_Submit(self) {
    //debugger;
    //验证:添加工作组
    if (typeof (workTeam_Valid) == "function") {
        return workTeam_Valid();
    }
    return true;
}
function btnTool_Save(self) {
    return true;
}
function btnTool_Back(self) {
    return true;
}
function btnTool_Delegate(self) {
    return true;
}
function btnTool_SendMail(self,orderid) {
    // window.open("SelPage/MailBuilder.aspx?orderid=" + orderid);
    var sFeatures="dialogHeight:400px;dialogWidth:590px;";
    var obj = window.showModalDialog("SelPage/MailBuilder.aspx?orderid=" + orderid+"&rdm="+Math.random(), "", sFeatures);
    if (obj=="true") {
        window.location.href += "&rdm=" + Math.random();
    }
    return false;
}
function btnTool_Print(self,orderid) {
    window.open("/web/project/PrintPage/OrderDetailPrint.aspx?orderid=" + orderid);
    return false;
} 
/*
说明：将日期字符串，转化为JS的Date对象，仅针对“yyyy-MM-dd”格式的字符串
-------------------------------------------------
*/
function GetJSDate(strDate) {
var Arr1 = strDate.split(/-/g);
var date = new Date(Arr1[0], Arr1[1] - 1, Arr1[2]);  //结束日期
return date;
}
/*
说明：给出红色(*)星号，提示文本框为必填项
-------------------------------------
inputid:文本框的客户端id
*/
function FieldRequired(inputid) {
var input = $("#"+inputid);
if (input.length > 0) {
var prevTD = input.parent().prev();
if (prevTD.prop("tagName").toUpperCase() == "TD") {
prevTD.append("(<a style='color:red;font-weight:bold;' title='该字段为必填'>*</a>)");
// prevTD.append("（*）");
}
}
}
/*
说明：用js绑定obj的Value变化而触发的事件
-------------------------------------
obj:    其值变化，一般为hidden
handle:处理函数名
param：要传递给handle方法的参数
*/
function JsBindValChangeEvent(obj,handle,param){
   // debugger;
    var eventHandler = handle;
    if (param)
    {
        eventHandler = function (e)
        {
            handle.call(obj,param);
        }
    }
    if(window.attachEvent)//IE
        obj.attachEvent("onpropertychange", eventHandler);
    else//FF
        obj.addEventListener("input", eventHandler, false);

}
/*
说明：用js绑定target的事件
-------------------------------------
target:    目标控件
eventName：事件名称，如click
handler: 处理函数名
argsObject：要传递给handle方法的参数
*/
function JsAttachEvent(target, eventName, handler, argsObject)
{   var eventHandler = handler;
    if(argsObject)
    {eventHander = function(e){
        handler.call(target,argsObject, e);
        }
    }
    if(window.attachEvent)//IE
        target.attachEvent("on" + eventName, eventHander );
    else//FF
        target.addEventListener(eventName, eventHander, false);
}
/*
说明：显示最新的描述信息
-------------------------------------
parm.descrType  描述类型
parm.container  （装载描述信息的）容器
*/
function RefreshDescription(parm) {
    var DescrType = parm.descrType;
    var container = parm.container;
    var str = this.value; 
    var id = str.split(/\*/)[0];
    GetRemoteDescription(DescrType, id, container);
}
/*
说明：用ajax调用功能页面，获取描述信息，填充到容器
----------------------------------------------
DescrType   描述类型
Key         对象ID
container   容器 
*/
function GetRemoteDescription(DescrType, Key, container) {
    $.ajax({
        type: "post",
        url: "/web/ServiceHandler/Description.ashx",
        dataType: "html",
        data: "descrtype=" + DescrType + "&objid=" + Key,
        success: function (Back) {
            container.empty();
            $(Back).appendTo(container);
        },
        error: function () { alert("远程获取数据失败！"); return false; }
    })
}
/*
说明：绑定描述信息自动刷新功能，到事件；并立即执行一次。    
---------------------------------------------------
HiddenID    存放对象ID的hidden控件，监视其值的变化.
Handler     要绑定到事件的，处理函数。
parm    参数传递
*/
function DealShowDescription(HiddenID, Handler, parm) {   
    var hdf = $("input[id$=" + HiddenID + "]");
    if (hdf.length>0) {
        JsBindValChangeEvent(hdf[0], Handler, parm); //RefreshDescription
        if (hdf.val()) { Handler.call(hdf[0], parm); }
    }
}
/*
说明：获取商店信息，并赋值到页面控件
-----------------------------------
hdfShopID 存放商店ID的控件
*/
function AssignShopInfo(hdfShopID) {
    var strShopid = hdfShopID.value;
    if (strShopid) {
        var shopid= strShopid.split(/\*/)[0];        
        var aj = $.ajax({
            type: "post",
            url: "/web/ServiceHandler/GetShop.ashx",
           // cache: false,
            dataType: "html",
            data: "shopid=" + shopid,
            success: function (Back) {
                var json = eval(Back);
                if (json) {
                    DeserialShopModel(json);
                }
            },
            error: function () { alert("远程获取数据失败！"); return false; }
        })
    }
}
function DeserialShopModel(jsonShop) {    
    var Prefix = "#ctl00_ContentPlaceHolder1_Wizard1_";   
    IfNullAssignVal(Prefix, "tbxAddress", jsonShop.Address);  
    IfNullAssignVal(Prefix, "tbxShopLev", jsonShop.ShopLev);
    IfNullAssignVal(Prefix, "tbxSaleVolume",jsonShop.SaleVolume);
    IfNullAssignVal(Prefix, "tbxShopTLCode",jsonShop.TLCode);
    IfNullAssignVal(Prefix, "tbxShopSquare",jsonShop.Square);
    IfNullAssignVal(Prefix, "tbxShopPromotor",jsonShop.ShopPromotor);
    IfNullAssignVal(Prefix, "tbxShopLinkman",jsonShop.ShopLinkman);
    IfNullAssignVal(Prefix, "tbxShopLinkmanTel",jsonShop.ShopLinkmanTel);
}
function IfNullAssignVal(Prefix, tbxID, value) {
    if (!$(Prefix + tbxID).val()) {
        $(Prefix + tbxID).val(value);
    }
}
/*
说明：展示紧急程度文字和图片
-------------------------------
    strDateStart    开始日期
    strDateEnd      结束日期
    container       容器
*/
function ShowUrgency(strDateStart, strDateEnd,container,usage) {
    //var dArr1 = strDateStart.split(/-/g);
    //debugger;
//    if (!strDateEnd || !strDateStart) { return; }
//    var dArr2 = strDateEnd.split(/-/g);
//    var date1 = new Date();  //开始日期
//    var date2 = new Date(dArr2[0], dArr2[1] - 1, dArr2[2]);  //结束日期  
    var date1 = strDateStart;  //开始日期
    var date2 = strDateEnd  //结束日期  

    var date3 = date2.getTime() - date1.getTime()  //时间差的毫秒数
    var days = Math.floor(date3 / (24 * 3600 * 1000))
    var descr, statusimg, imgroot;
    imgroot =  "/Image/proj/";
    if (days <= 3) {
        descr = "非常紧急(1~3天)";
        statusimg = imgroot+"UrgencyBar_1.jpg";
    } else if (days >= 4 && days <= 10) {
        descr = "紧急（4~10天）";
        statusimg = imgroot+ "UrgencyBar_2.jpg";
    } else if (days >= 11 && days <= 30) {
        descr = "正常（11~30）";
        statusimg =  imgroot+"UrgencyBar_3.jpg";
    } else if (days >= 31 ) {
        descr = "待定（31天以上）";
        statusimg =  imgroot+"UrgencyBar_4.jpg";
    }
    if (usage == undefined || usage == "DefaultDisplay") {
        $(container).empty();
        $(container).append("<img src='" + statusimg + "' style='width:250px;height:22px;left:-2px;'>"); //
    } else {//usage == "PrintDisplay"
     }
    var descrContainer;
    if ($(container).next().length > 0) {
        descrContainer = $(container).next();
        descrContainer.empty();
    } else {
        descrContainer = container;
    }
    descrContainer.append("<label>" + descr + "</label>");
}
/*
说明：折叠详细信息页的信息块
*/
function fold(obj) {
    //debugger;
    var divtitle = $(obj).parent();
    var divinfo = divtitle.next();
    if ($(obj).prop("src").indexOf("zk.gif")>0) {
        $(obj).prop("src","/image/proj/zd.gif")
        divinfo.show();
    } else {
        $(obj).prop("src", "/image/proj/zk.gif")
        divinfo.hide();
    }
}
/*
说明：点击"×"后，调用ajax删除记录和文件
-------------------------------------------
lnk :"×"所在a元素

*/
function fileDelete(lnk) {
    var tr = $(lnk).parent().parent();
    var td = $("td", tr).eq(0);
    
    var fileid = $("#fid", td).val();
    var filepath = $("a", td).prop("href");

    var aj = $.ajax({
        type: "post",
        url: "/web/ServiceHandler/FileDel.ashx",
        // cache: false,
        dataType: "html",
        data: "fileid=" + fileid + "&filepath=" + filepath,
        success: function (Back) {
            var json = eval(Back);
            if (json) {
                if (json.result == "True") {
                    alert("删除成功！");
                    $(tr).remove();
                } else {
                    alert("删除出错：" + json.msg);
                }
            }
        },
        error: function () { alert("远程获取数据失败！"); return false; }
    })
}
